package com.github.zy.rpc.service.handler;

import com.alibaba.fastjson.JSON;
import com.github.zy.rpc.constants.Profile;
import com.github.zy.rpc.session.Session;
import com.github.zy.rpc.common.protocol.DefaultMessagePacket;
import com.github.zy.rpc.common.protocol.MessagePacketBuilder;

/**
 * @version 1.0 created by zy on 2020/4/28 14:15
 */
public interface ServerSender {

    void sendToClient(String moduleId, String urlMapping, Object msg);

    void sendToClient(String moduleId, String urlMapping, Profile profile, Object msg);

    void sendToClient(String moduleId, String urlMapping, String ip, int port, Object msg);

    void sendToClient(String moduleId, String urlMapping, Profile profile, String ip, int port, Object msg);

    void sendToClient(Session session);

    default DefaultMessagePacket buildRequestMessagePacket(Object msg, String moduleId, String urlMapping) {
        return MessagePacketBuilder.buildBasicRequest()
                .moduleId(moduleId).urlMapping(urlMapping).payload(JSON.toJSONString(msg)).build();
    }
}
